1
หกหลักสำคัญของกระบวนการพัฒนาโมเดลใน PyTorch
EvoClass-AI002Lecture 2
00:00

เฟรมเวิร์ก PyTorch ถูกสร้างขึ้นบนแนวทางมาตรฐานและมีประสิทธิภาพสูง บทเรียนนี้แนะนำ กระบวนการหกขั้นตอน ซึ่งเป็นแบบจำลองสำหรับ ทุก โครงการเรียนรู้เชิงลึกต่อไป ตั้งแต่การกำหนดโครงสร้างโมเดล ไปจนถึงการบันทึกค่าพารามิเตอร์สุดท้าย ขั้นตอนเหล่านี้สร้างเส้นทางที่ชัดเจนและติดตามได้สำหรับการพัฒนาโมเดล

ภาพรวมของกระบวนการเรียนรู้ของเครื่องที่มาตรฐาน

เราใช้ปัญหาการถดถอยเชิงเส้นง่ายๆ เป็นตัวอย่างเพื่อแสดงขั้นตอนทั้งหกที่จำเป็นต้องทำ การเข้าใจโครงสร้างนี้เป็นสิ่งสำคัญ เพราะมันกำหนดวิธีการจัดการข้อมูล วิธีการปรับแต่งพารามิเตอร์ผ่าน การแพร่กลับ (backpropagation)และวิธีการนำไปใช้งานโมเดลที่ได้ผลลัพธ์

หลักการโครงสร้าง

หกหลักนี้ช่วยให้มั่นใจในความแข็งแรงและความชัดเจนในการแยกงานในโปรเจกต์การเรียนรู้ของเครื่องของคุณ:

  • จุดโฟกัสหลัก (การแยกหน้าที่): การกำหนดขอบเขตระหว่างการโหลดข้อมูล สถาปัตยกรรมโมเดล และตรรกะการปรับแต่ง เพื่อรักษาความเป็นโมดูลาร์
  • การเชื่อมโยงสำคัญ (Autograd): หลักที่ 3 และ 4 (การคำนวณความผิดพลาด/ออปติไมเซอร์ และการฝึกอบรม) พึ่งพา Autograd เครื่องมือในการคำนวณเกรเดียนต์ที่ถูกต้อง
  • เป้าหมาย (การนำออกใช้งาน): เพื่อสร้างโมเดลที่ถูกแปลงเป็นลำดับ (หลักที่ 6) ที่สามารถทำงานได้อย่างมีประสิทธิภาพในสภาพแวดล้อมเป้าหมายใด ๆ (ทั้งหน่วยประมวลผลกลางหรือฮาร์ดแวร์เฉพาะ)
ความสำคัญของการแบ่งข้อมูลฝึกอบรม/ทดสอบ
หลักที่ 1 (การเตรียมข้อมูล) ต้องมีการแยกข้อมูลอย่างรอบคอบ โมเดล ต้อง เรียนรู้จากชุดข้อมูลฝึกอบรมเท่านั้น และประสิทธิภาพของมันจะต้องถูกตรวจสอบโดยใช้ชุดข้อมูลทดสอบที่ไม่เคยเห็นมาก่อน (หลักที่ 5) เพื่อให้มั่นใจว่าโมเดลสามารถทั่วไปได้ ต้อง ถูกตรวจสอบโดยใช้ชุดข้อมูลทดสอบที่ไม่เคยเห็นมาก่อน (หลักที่ 5) เพื่อให้มั่นใจว่าโมเดลสามารถทั่วไปได้
workflow.py
TERMINALbash — pytorch-env
> Ready. Click "Run" to simulate the workflow.
>
WORKFLOW STAGE Overview

Visualizing the Process: The workflow transforms raw input data (Pillar 1) through the network weights (Pillar 2) to yield a highly optimized, savable file (Pillar 6).
Question 1
Which step immediately follows the calculation of the Loss during the training loop?
Calling loss.backward() (Backpropagation)
Saving the model state dictionary
Performing the forward pass again
Running the evaluation loop
Question 2
What is the primary purpose of Pillar 3 (Loss and Optimizer Setup)?
Defining how error is measured and how weights are adjusted.
Defining the model's architecture (layers).
Splitting the data into training and testing sets.
Question 3
What is required for a parameter to be adjustable during the training loop?
It must be defined as a subclass of nn.Module and have requires_grad=True.
It must be converted to a NumPy array first.
It must be saved to disk before training starts.
Challenge: Ordering the Training Cycle
Arrange the four core operations within the Training Loop (Pillar 4).
You have completed the Forward Pass and calculated the loss. List the remaining steps in chronological order for a single training iteration.
Step 1
What is the correct order for the final three steps of one training iteration?
Solution:
  1. Zero the gradients (optimizer.zero_grad())
  2. Backward Pass (loss.backward())
  3. Update Weights (optimizer.step())
Step 2
If the model performs poorly on the Test set (Pillar 5) but well on the Training set, which Pillar needs review?
Solution:
Pillar 2 (Model Definition—potential overfitting due to complexity) or Pillar 1 (Data Preparation—training/testing sets may not be representative).